package com.utils;

import android.util.Log;

//http://blog.csdn.net/lmj623565791/article/details/38965311
public class L {

	private L()  
    {  
        /* cannot be instantiated */  
        throw new UnsupportedOperationException("cannot be instantiated");  
    }  
  
    public static boolean isDebug = true;// 是否需要打印bug，可以在application的onCreate函数里面初始化  
    private static final String TAG = "way"; 
    public static final boolean DEBUG_SYSOUT = true;
  
    ////////////////////////////////// 下面四个是默认tag的函数  
    public static void i(String msg)  
    {  
        if (isDebug)  
            Log.i(TAG, msg);  
    }  
  
    public static void d(String msg)  
    {  
        if (isDebug)  
            Log.d(TAG, msg);  
    }  
  
    public static void e(String msg)  
    {  
        if (isDebug)  
            Log.e(TAG, msg);  
    }  
  
    public static void v(String msg)  
    {  
        if (isDebug)  
            Log.v(TAG, msg);  
    }  
    
    
    //////////////////////////////////////////////带类名标识
    public static void i_c(String msg)  
    {  
        if (isDebug)  {
             Log.v(TAG, getClassName()+"---"+msg);
        }
    }  
  
    public static void d_c(String msg)  
    {  
        if (isDebug)  
            Log.d(TAG, getClassName()+"---"+msg);  
    }  
  
    public static void e_c(String msg)  
    {  
        if (isDebug)  
            Log.e(TAG, getClassName()+"---"+msg);  
    }  
  
    public static void v_c(String msg)  
    {  
        if (isDebug)  
            Log.v(TAG, getClassName()+"---"+msg);  
    }
    
    
    ////////////////////////////////////////////// 下面是传入自定义tag的函数  
    public static void i(String tag, String msg)  
    {  
        if (isDebug)  
            Log.i(tag, msg);  
    }  
  
    public static void d(String tag, String msg)  
    {  
        if (isDebug)  
            Log.d(tag, msg);  
    }  
  
    public static void e(String tag, String msg)  
    {  
        if (isDebug)  
            Log.e(tag, msg);  
    }  
  
    public static void v(String tag, String msg)  
    {  
        if (isDebug)  
            Log.v(tag, msg);  
    }  
    
    //SYSTEM
    /**
     * Print the array of stack trace elements of this method in black.
     *
     * @return
     */
    public static void printCallHierarchy() {
            String tag = getClassName();
            String method = callMethodAndLine();
            String hierarchy = getCallHierarchy();
            Log.v(tag, method + hierarchy);
            if (DEBUG_SYSOUT) {
                System.out.println(tag + "  " + method + hierarchy);
            }
    }

    /**
     * Print debug log in blue.
     *
     * @param object The object to print.
     */
    public static void printMyLog(Object object) {
            String tag = "MYLOG";
            String method = callMethodAndLine();
            String content = "";
            if (object != null) {
                content = object.toString() + "                    ----    "
                        + method;
            } else {
                content = " ## " + "                ----    " + method;
            }
//            Log.d(tag, content);
            if (DEBUG_SYSOUT) {
                System.out.println(tag + "  " + content + "  " + method);
            }
    }
    //打印一个当前位置信息，类+方法
    public static void print() {
            String tag = getClassName();
            String method = callMethodAndLine();
            Log.v(tag, method);
            if (DEBUG_SYSOUT) {
                System.out.println(tag + "  " + method);
            }
    }
    
    
    ////////////////////////////////////////////////////////////////////////内部处理
    private static String getClassName() {
        String result = "";
        StackTraceElement thisMethodStack = (new Exception()).getStackTrace()[2];
        result = thisMethodStack.getClassName();
        return result;
    }
    
    /**
     * Realization of double click jump events.
     *
     * @return
     */
    private static String callMethodAndLine() {
        String result = "at ";
        StackTraceElement thisMethodStack = (new Exception()).getStackTrace()[2];
        result += thisMethodStack.getClassName() + "";
        result += thisMethodStack.getMethodName();
        result += "(" + thisMethodStack.getFileName();
        result += ":" + thisMethodStack.getLineNumber() + ")  ";
        return result;
    }
    
    private static String getCallHierarchy() {
        String result = "";
        StackTraceElement[] trace = (new Exception()).getStackTrace();
        for (int i = 2; i < trace.length; i++) {
            result += "\r\t" + trace[i].getClassName() + ""
                    + trace[i].getMethodName() + "():"
                    + trace[i].getLineNumber();
        }
        return result;
    }
}
